package com.yizisu.playerlibrary.view.video_view.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.yizisu.playerlibrary.IYzsPlayer
import com.yizisu.playerlibrary.R
import com.yizisu.playerlibrary.view.video_view.helper.*

/**
 * 播放器的根view
 */
open class BasePlayerRootView : FrameLayout {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    /**
     * 设置播放器并且处理实现了[IPlayerHelper]的类
     */
    fun setPlayerAndInitHelper(
        player: IYzsPlayer<IYzsPlayer.Model>,
        block: ((IPlayerConfig) -> Unit)? = null
    ) {
        val config = IPlayerConfigImpl()
        //region 默认配置
        config.updateShowOrHideController(0f)
        config.updateSpeed(
            listOf(
                Pair(0.5f, "x "), Pair(1f, "x "), Pair(1.5f, "x "), Pair(2f, "x "), Pair(3f, "x ")
            )
        )
        config.updateMaxSwipeDuration(Pair(5 * 60 * 1000/*五分钟*/, 12 * 60 * 1000/*十二分钟*/))
        config.updateLongPressedSpeed(3f)
        config.updatePlayerControllerBarHelper(PlayerControllerBarHelper(config))
        config.updatePlayer(player)
        //endregion
        block?.invoke(config)
        //配置player
        PlayerHelper().configPlayerHelper(this, config)
    }
}